<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents');?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("#independent_change_price_link").colorbox({width:"800", height:"650", iframe:true});
	$("#multiselect").multiselect({height: 260, minWidth: 160});
	$(".detail").colorbox({width:"60%", height:"80%", iframe:true});
	$("#dialog_price").dialog({autoOpen:false,modal:true,height:250, width:400});
	$("#dialog_quantity").dialog({autoOpen:false,modal:true,height:200, width:300});
	var purchase_categories_data = <?=$purchase_categories?>;
	$(document).mselect(purchase_categories_data, 'product_categories_id','product_categories_id', "<?=isset($_GET['product_categories_id'])?$_GET['product_categories_id']:0?>");
	$(".m_revise_price").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选中产品列表！");
			return false;
		}
		$("#dialog_price").find("input[name='ids']").val(ids);
		$("#dialog_price").dialog({
			autoOpen: true,  
            title: '批量调整Amazon上架产品价格',
            buttons: {  
                "关闭": function(){$(this).dialog('close');},  
                "确定": function(){$(this).attr('action', "<?=url('Online::Amazon/Upload', array('type' => 'price', 'shop_id' => isset($_GET['shop_id']) ? $_GET['shop_id'] : ''))?>").submit();}  
            },
            close: function(){$("#dialog_price")[0].reset();}
		});
	});
	$(".m_revise_quantity").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选中产品列表！");
			return false;
		}
		$("#dialog_quantity").find("input[name='ids']").val(ids);
		$("#dialog_quantity").dialog({
			autoOpen: true,  
            title: '批量调整Amazon上架产品库存',
            buttons: {  
                "关闭": function(){$(this).dialog('close');},  
                "确定": function(){$(this).attr('action', "<?=url('Online::Amazon/Upload', array('type' => 'quantity', 'shop_id' => isset($_GET['shop_id']) ? $_GET['shop_id'] : ''))?>").submit();}  
            },
            close: function(){$("#dialog_quantity")[0].reset();}
		});
	});
	$(".independent_change_price").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选中产品列表！");
			return false;
		}
		$("#independent_change_price_link").attr('href', "<?php echo url('Online::Amazon/IndependentChangeProductPrice')?>&ids=" + ids).click();
	});
	$(".check_btn").click(function(){
		if ($(this).is(":checked"))
		{
			$(".disable_flag").attr("disabled", true);
			$(this).parent().parent().parent().find("input[type='checkbox']").attr("checked", false);
			$(this).attr('checked', true);
			$(this).parent().next().attr("disabled", false);
			$(this).parent().next().next().attr("disabled", false);
			$(this).parent().next().next().next().attr("disabled", false);
			$(this).parent().next().next().next().next().attr("disabled", false);
			$(this).parent().next().next().next().next().next().attr("disabled", false);
		}
		else
		{
			$(".disable_flag").attr("disabled", true);
			$("#dialog_price").find("input[type='checkbox']").attr("checked", false);
		}
	});
	$(".del").live("click", function(){
		if ( ! confirm("确定删除？"))
		{
			return false;
		}
		else
		{
			$(this).parent().parent().remove();
		}
	});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
});
</script>
<style>
.blur
{
	cursor: pointer;
	border: none;
}
</style>
<fieldset><legend>查询条件</legend>
<form method="get" action="">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>SKU</th>
	<td><input type="text" name="number" size="50" value="<?=isset($_GET['number']) ? $_GET['number']:''?>" /> 说明：多个SKU用英文逗号分开</td>
</tr>
<tr>
	<th>模糊查找</th>
	<td><input type="text" name="number_follow" value="<?=isset($_GET['number_follow']) ? $_GET['number_follow'] : ''?>" /></td>
</tr>
<tr>
	<th>ASIN</th>
	<td><input type="text" name="shop_item_id" value="<?=isset($_GET['shop_item_id']) ? $_GET['shop_item_id'] : ''?>" /></td>
</tr>
<tr>
	<th>产品类别</th>
	<td colspan="3"><input type="hidden" name="product_categories_id" id="product_categories_id" /></td>
</tr>
<tr>
	<th>选择店铺</th>
	<td>
		<select name="shop_id[]" multiple="multiple" id="multiselect">
		<?foreach ($shop_group as $k => $sg):?>
		<optgroup label="<?=$k?>">
		<?foreach ($sg as $s):?>
		<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && is_array($_GET['shop_id']) && in_array($s['id'], $_GET['shop_id']))echo "selected='selected'";elseif (isset($_GET['shop_id']) && $_GET['shop_id'] == $s['id'])echo "selected='selected'"?>><?=$s['name']?></option>
		<?endforeach;?>
		</optgroup>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>创建时间</th>
	<td>
		<input type="text" name="start_create_time" class="datepicker" value="<?=isset($_GET['start_create_time']) ? $_GET['start_create_time'] : ''?>" /> to
		<input type="text" name="end_create_time" class="datepicker" value="<?=isset($_GET['end_create_time']) ? $_GET['end_create_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>店铺库存</th>
	<td>
		<select name="quantity_operator1">
			<option value="">请选择..</option>
			<option value="=" <?if(isset($_GET['quantity_operator1'])&&$_GET['quantity_operator1']=='=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if(isset($_GET['quantity_operator1'])&&$_GET['quantity_operator1']=='>=')echo "selected='selected'"?>>&gt;=</option>
			<option value="<=" <?if(isset($_GET['quantity_operator1'])&&$_GET['quantity_operator1']=='<=')echo "selected='selected'"?>>&lt;=</option>
		</select>
		<input type="text" name="quantity1" value="<?=isset($_GET['quantity1']) ? $_GET['quantity1']:''?>" />
	</td>
</tr>
<tr>
	<th>系统库存</th>
	<td>
		<select name="quantity_operator2">
			<option value="">请选择..</option>
			<option value="=" <?if(isset($_GET['quantity_operator2'])&&$_GET['quantity_operator2']=='=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if(isset($_GET['quantity_operator2'])&&$_GET['quantity_operator2']=='>=')echo "selected='selected'"?>>&gt;=</option>
			<option value="<=" <?if(isset($_GET['quantity_operator2'])&&$_GET['quantity_operator2']=='<=')echo "selected='selected'"?>>&lt;=</option>
		</select>
		<input type="text" name="quantity2" value="<?=isset($_GET['quantity2']) ? $_GET['quantity2']:''?>" />
	</td>
</tr>
<tr>
	<th>状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/online_amazon_product_status') as $p):?>
		<label><input type="checkbox" name="status[<?=$p['value']?>]" value="<?=$p['value']?>" <?if (isset($_GET['status']) &&  array_key_exists($p['value'], $_GET['status'])) echo "checked='checked'"?> /> <?=$p['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>价格比较</th>
	<td>
		<label><input type="radio" name="price_compare" value="0" <?php if (isset($_GET['price_compare']) && $_GET['price_compare'] == 0) echo "checked='checked'"?>> 相等</label>
		<label><input type="radio" name="price_compare" value="1" <?php if (isset($_GET['price_compare']) && $_GET['price_compare'] == 1) echo "checked='checked'"?>> 不相等</label>
	</td>
</tr>
<tr>
	<th>配送渠道</th>
	<td>
		<?foreach (Q::ini('custom_flag/online_amazon_fulfillment_channel') as $o):?>
		<label><input type="checkbox" name="channel[<?=$o['value']?>]" value="<?=$o['value']?>" <?if (isset($_GET['channel']) &&  array_key_exists($o['value'], $_GET['channel'])) echo "checked='checked'"?> /> <?=$o['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>采购状态</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/product_purchase_status') as $ps):?>
		<label><input type="checkbox" name="purchase_status[<?=$ps['value']?>]" value="<?=$ps['value']?>" <?if (isset($_GET['purchase_status'][$ps['value']]) && $_GET['purchase_status'][$ps['value']] == $ps['value'])echo "checked=checked"?> /> <font color="#<?=$ps['color']?>"><?=$ps['name']?></font></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>销售状态</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/product_sales_status') as $ss):?>
		<label><input type="checkbox" name="sales_status[<?=$ss['value']?>]" value="<?=$ss['value']?>" <?if (isset($_GET['sales_status'][$ss['value']]) && $_GET['sales_status'][$ss['value']] == $ss['value'])echo "checked=checked"?> /> <font color="#<?=$ss['color']?>"><?=$ss['name']?></font></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th><input type="hidden" name="is_search" value="1" /></th>
	<td><input type="submit" class="button" value="查询" /></td>
	<td>
		<?if (is_file(Q::ini('custom_system/wrong_listing_dir') . date('Y-m-d', CURRENT_TIMESTAMP) . '-Amazon.xls')):?><a href="<?=Q::ini('custom_system/wrong_listing_url') . date('Y-m-d', CURRENT_TIMESTAMP) .  '-Amazon.xls'?>">下载错误SKU表</a> /<?endif;?>
		<?if(isset($products)):?><a href="<?=url('Online::Amazon/Download', array('url_arr_json' => $url_arr_json))?>" >下载报表</a><?endif;?>
	</td>
</tr>
</table>
</form>
</fieldset>
<?if (isset($products)):?>
<table class="list_table" width="100%" id="list">
<tr>
	<th></th>
	<th>SKU</th>
	<th>所属店铺</th>
	<th width="80">ASIN</th>
	<th>产品名称</th>
	<th>采购状态</th>
	<th>销售状态</th>
	<th width="40">状态</th>
	<th>系统库存</th>
	<th width="40">库存</th>
	<th>配送渠道</th>
	<th>折前价</th>
	<th>折后价<br /><font color="#bbb">+shipping</font></th>
	<th>竞价<br /><font color="#bbb">+shipping</font></th>
	<th width="80">创建时间</th>
</tr>
<?foreach ($products as $p):?>
<tr>
	<td><input type="checkbox" value="<?=$p['id']?>" /></td>
	<td title="查看详细">
		<a class="detail" href="<?=url('Online::Amazon/Detail', array('sku' => $p['sku'], 'shop_id' => $p['shop_id']))?>"><?=$p['sku']?></a>
		<?if ($p['product_name']):?>
			<?if ($p['pic_url']):?>
				<?$pretty_photo_number = 0;?>
				<?foreach ($p['pic_url'] as $pp):?>
				<a rel="pretty_photo[<?=$p['id']?>]" href="<?=$pp?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
				<?$pretty_photo_number = 1;?>
				<?endforeach;?>
			<?endif;?>
			<?if ($p['sales_trend']):?>
				<span class="<?=Helper_BSS_Normal::getIniOne('product_sales_trend', 'value', $p['sales_trend'], 'icon_class') ?>"></span>
			<?endif;?>
		<?endif;?>
	</td>
	<td><?=$p['shop_name']?></td>
	<td><?=$p['shop_item_id']?></td>
	<td title="<?=$p['product_name']?>"><?=mb_substr($p['product_name'], 0, 30, 'utf-8')?></td>
	<td><font color="#<?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $p['purchase_status'], 'color')?>"><?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $p['purchase_status'], 'name')?></font></td>
	<td><font color="#<?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $p['sales_status'], 'color')?>"><?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $p['sales_status'], 'name')?></font></td>
	<td><?=Helper_BSS_Normal::getIniOne('online_amazon_product_status', 'value', $p['status'], 'name')?></td>
	<td><?=$p['available_quantity']?></td>
	<td><?=$p['quantity']?></td>
	<td><?=Helper_BSS_Normal::getIniOne('online_amazon_fulfillment_channel', 'value', $p['channel'], 'name')?></td>
	<td><?=$p['price']?></td>
	<td <?=($p['competitive_price'] != $p['listing_price']) ? 'bgcolor="red"' : '';?> title="更新时间：<?=$p['update_listing_price_time']?>"><?=$p['listing_price'] . '<br />' . (empty($p['listing_price_shipping_fee']) ? '' : '<font color="#bbb">+' . $p['listing_price_shipping_fee'] . '</font>')?></td>
	<td <?=($p['competitive_price'] != $p['listing_price']) ? 'bgcolor="red"' : '';?> title="更新时间：<?=$p['update_competitive_price_time']?>"><?=$p['competitive_price'] . '<br />' . (empty($p['competitive_price_shipping_fee']) ? '' : '<font color="#bbb">+' . $p['competitive_price_shipping_fee'] . '</font>')?></td>
	<td><?=substr($p['open_time'], 0, 10)?></td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td rowspan="1"><label><input type="checkbox" id="check_all" /> 全选</label></td>
	<td align="left">批量操作：
		<input type="button" class="button m_revise_price" value="批量调整价格" />
		<input type="button" class="button m_revise_quantity" value="批量调整库存" />
		<input type="button" class="button independent_change_price" value="独立修改价格" />
		<a style="display: none" href="" id="independent_change_price_link"></a>
	</td>
</tr>
</table>
<form method="post" id="dialog_price">
<input type="hidden" name="ids" />
<p>
<label><input type="checkbox" name="by_price" class="check_btn" value="1" checked="checked"/> 价格：</label>
<input type="text" name="price" size="7" class="disable_flag" /> ※ 折前价
</p>
<p>
<label><input type="checkbox" name="by_adjust" class="check_btn" value="1" /> 调整：</label>
<select name="adjust_operate" disabled="disabled" class="disable_flag">
<option value="+">+</option>
<option value="-">-</option>
</select>
<input type="text" name="adjust_price" size="9" disabled="disabled" class="disable_flag"/>
</p>
<p>
<label><input type="checkbox" name="by_discount" class="check_btn" value="1" /> 打折：</label>
<select name="discount" disabled="disabled" class="disable_flag">
<option value="">请选择</option>
<?for ($i=0.1; $i<2.1; $i+=0.1):?>
<option value="<?=$i;?>"><?=sprintf('%.1f', $i)?></option>
<?endfor;?>
</select> ※ <font color="red">系统折后价</font>*折扣<br>
<input type="text" name="start_time" class="datepicker disable_flag" size="10" disabled="disabled" placeholder="打折开始日期" style="margin-left: 4.8em; margin-top: 0.5em;"> to <input type="text" name="end_time" class="datepicker disable_flag" disabled="disabled" size="10"/ placeholder="打折结束日期"> ※ 不填默认为三年
</p>
</form>
<form method="post" id="dialog_quantity">
<input type="hidden" name="ids" />
<p>
<label><input type="checkbox" name="by_quantity" class="check_btn" value="1" checked="checked"/> 库存：</label>
<input type="text" size="7" name="quantity" class="disable_flag"/>
</p>
<p>
<label><input type="checkbox" name="by_adjust" value="1" class="check_btn" /> 调整：</label>
<select name="adjust_operate" disabled="disabled" class="disable_flag">
<option value="+">+</option>
<option value="-">-</option>
</select>
<input type="text" name="adjust_quantity" size="9" disabled="disabled" class="disable_flag"/>
</p>
<p>
<label><input type="checkbox" name="by_latency" value="1" onclick="if ($(this).is(':checked')){$(this).parent().next().attr('disabled', false);}else{$(this).parent().next().attr('disabled', true);}"/> 货期：</label>
<select name="latency" disabled="disabled">
	<option value="">请选择</option>
	<?for ($i=1; $i<31; $i+=1):?>
	<option value="<?=$i?>"><?=$i?></option>
	<?endfor;?>
</select> 天
</p>
</form>
<?endif;?>
<?php $this->_endblock();?>